﻿@model LynxWiki.ViewModels.AttachFileInfo

<tr>
    <td class="TableCell">
        @if (Model.AuthOK) {
            <a href="@Path.Combine(HttpContext.Current.Server.MapPath("~/" + Model.DirectoryPath), Model.FileName)" >@Model.FileName</a>
        } else {
            @Html.DisplayFor(model => model.FileName)
        }
    </td>
    <td class="TableCell">@Model.Length</td>
    <td class="TableCell">@Html.DisplayFor(model => model.CreatedOn)</td>
    <td class="TableCell">@Html.DisplayFor(model => model.WikiText)</td>
    @if (Model.AuthOK) {
        <td class="TableCell">
            @using (Html.BeginForm("ListVersions", "Attachment",  FormMethod.Post)) {
                <input type="hidden" name="FileName" value="@Model.FileName" />
                <input type="hidden" name="DirectoryPath" value="@Model.DirectoryPath" />
                <input type="hidden" name="NamespaceSelected" value="@Model.NameSpace" />
                <input type="submit" name="listFileVersions" value="Version Info" />
            }
        </td>
        if (Model.Updateable && !Model.CheckedOut) {
            <td class="TableCell">
                @using (Html.BeginForm("CheckOut", "Attachment",  FormMethod.Post)) {
                    <input type="hidden" name="FileName" value="@Model.FileName" />
                    <input type="hidden" name="DirectoryPath" value="@Model.DirectoryPath" />
                    <input type="hidden" name="NamespaceSelected" value="@Model.NameSpace" />
                    <input type="submit" name="checkOut" value="Check Out" />
                }
            </td>
        }
        if (User.Identity.Name == Model.CheckedOutUser && Model.CheckedOut) {
            <td class="TableCell">
                @using (Html.BeginForm("CheckIn", "Attachment", FormMethod.Post)) {
                    <input type="hidden" name="FileName" value="@Model.FileName" />
                    <input type="hidden" name="DirectoryPath" value="@Model.DirectoryPath" />
                    <input type="hidden" name="NamespaceSelected" value="@Model.NameSpace" />
                    <input type="submit" name="checkIn" value="Check In" />
                }
            </td>
        }
    }
    @if (User.IsInRole("WikiAdmin")) {
        <td class="TableCell">
            @using (Html.BeginForm("Delete", "Attachment",  FormMethod.Post)) {
                <input type="hidden" name="FileName" value="@Model.FileName" />
                <input type="hidden" name="DirectoryPath" value="@Model.DirectoryPath" />
                <input type="hidden" name="NamespaceSelected" value="@Model.NameSpace" />
                <input type="submit" name="deleteFile" value="Delete File" />
            }
        </td>
        if (Model.CheckedOut) {
        <td class="TableCell">
            @using (Html.BeginForm("CancelCheckOut", "Attachment",  FormMethod.Post)) {
                <input type="hidden" name="FileName" value="@Model.FileName" />
                <input type="hidden" name="DirectoryPath" value="@Model.DirectoryPath" />
                <input type="hidden" name="NamespaceSelected" value="@Model.NameSpace" />
                <input type="submit" name="cancelCheckOut" value="Cancel CheckOut" />
            }
        </td>
        }
    }
</tr>